﻿CREATE PROCEDURE [dbo].[utl_PruneAuditTable]
@HowMuch VARCHAR (50)=NULL, @ProcessName VARCHAR (50)=NULL, @Instance UNIQUEIDENTIFIER=NULL
AS
BEGIN
	-- start of utl_LogMsg setup --
	DECLARE @Message      VARCHAR(MAX);        SET @Message = ISNULL(@Message, '{message is null}')
	DECLARE @RowsAffected INT;                 SET @RowsAffected = NULL
	DECLARE @ErrorCode    INT;                 SET @ErrorCode = NULL
	/*DECLARE @ProcessName  sysname;             SET @ProcessName = NULL*/
	DECLARE @StepName     sysname;             SET @StepName = ISNULL(@StepName, OBJECT_NAME(@@PROCID))
	/*DECLARE @Instance	    UNIQUEIDENTIFIER*/ SET @Instance = ISNULL(@Instance, NEWID())
	-- end of utl_LogMsg setup --

	DECLARE @RC     INT
	DECLARE @Table  sysname

	IF @HowMuch IS NULL
	BEGIN
		RAISERROR('Must specify a value for @HowMuch.', 16, 1)
		RETURN 1
	END

	SET @Message = 'Executing utl_PruneMessageLog'
	EXECUTE [dbo].[utl_LogMsg] @Message, @RowsAffected, @ErrorCode, @ProcessName, @StepName, @Instance

	SET @Table = 'Audit'
	EXECUTE @RC = [dbo].[utl_PruneTable] @Table, @HowMuch, @ProcessName, @Instance

	RETURN @RC
END

